package com.ruoyi.module.productCatalog.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.module.productCatalog.vo.ProductCatalogVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.module.productCatalog.domain.ProductCatalog;
import com.ruoyi.module.productCatalog.service.IProductCatalogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 页签2.0Controller
 * 
 * @author yqq
 * @date 2024-04-15
 */
@RestController
@RequestMapping("/api/productCatalog")
public class ProductCatalogController extends BaseController
{
    @Autowired
    private IProductCatalogService productCatalogService;

    /**
     * 查询页签2.0列表
     */
    @PreAuthorize("@ss.hasPermi('api:productCatalog:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductCatalog productCatalog)
    {
        List<ProductCatalogVO> list = productCatalogService.selectAllProductCatalogList(productCatalog);
        return getDataTable(list);
    }

    /**
     * 导出页签2.0列表
     */
    @PreAuthorize("@ss.hasPermi('api:productCatalog:export')")
    @Log(title = "页签2.0", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductCatalog productCatalog)
    {
        List<ProductCatalog> list = productCatalogService.selectProductCatalogList(productCatalog);
        ExcelUtil<ProductCatalog> util = new ExcelUtil<ProductCatalog>(ProductCatalog.class);
        util.exportExcel(response, list, "页签2.0数据");
    }

    /**
     * 获取页签2.0详细信息
     */
    @PreAuthorize("@ss.hasPermi('api:productCatalog:query')")
    @GetMapping(value = "/{catalogId}")
    public AjaxResult getInfo(@PathVariable("catalogId") Long catalogId)
    {
        return success(productCatalogService.selectProductCatalogByCatalogId(catalogId));
    }

    /**
     * 新增页签2.0
     */
    @PreAuthorize("@ss.hasPermi('api:productCatalog:add')")
    @Log(title = "页签2.0", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ProductCatalog productCatalog)
    {
        return toAjax(productCatalogService.insertProductCatalog(productCatalog));
    }

    /**
     * 修改页签2.0
     */
    @PreAuthorize("@ss.hasPermi('api:productCatalog:edit')")
    @Log(title = "页签2.0", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody ProductCatalog productCatalog)
    {
        return toAjax(productCatalogService.updateProductCatalog(productCatalog));
    }

    /**
     * 删除页签2.0
     */
    @PreAuthorize("@ss.hasPermi('api:productCatalog:remove')")
    @Log(title = "页签2.0", businessType = BusinessType.DELETE)
	@GetMapping("/delete/{catalogIds}")
    public AjaxResult remove(@PathVariable Long catalogId)
    {
        productCatalogService.deleteAllProductCatalog(catalogId);
        return success();
    }
}
